<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Volunteer
 *
 * @property int $id 主键
 * @property int $groupid
 * @property string|null $name 姓名
 * @property int|null $gender 性别
 * @property string|null $tel 电话
 * @property string $image 照片
 * @property int|null $state 审核状态
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\MeetingGroup $group
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\MeetingVolunteerSignin[] $signins
 * @property-read int|null $signins_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereGender($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereGroupid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereImage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereState($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereTel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingVolunteer whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class MeetingVolunteer extends Model
{
    protected $table = 'meeting_volunteer';
    protected $primaryKey = 'id';
    protected $fillable = ['name', 'tel', 'image', 'groupid', 'gender', 'state'];

    /**
     * @param $value
     * @return string
     */
    public function getImageAttribute($value)
    {
        return $value ? image_url($value) : $value;
    }

    /**
     * @param $value
     */
    public function setImageAttribute($value)
    {
        $this->attributes['image'] = strip_image_url($value);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function group()
    {
        return $this->belongsTo(MeetingGroup::class, 'groupid', 'groupid');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function signins()
    {
        return $this->hasMany(MeetingVolunteerSignin::class, 'volunteer_id', 'id');
    }
}
